package com.ddm.controller.vx;


import com.ddm.constant.MessageConstant;
import com.ddm.context.BaseContext;
import com.ddm.exception.DataErrorException;
import com.ddm.result.Result;
import com.ddm.service.vxService.UserService;
import com.ddm.vo.vxVo.UserVo;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 展示用户信息
 */
@RestController
@RequestMapping("/user/user/userinfo")
@Slf4j
public class UserInfoController {

    @Autowired
    UserService userService;

    @GetMapping
    @ApiOperation("获取已登录用户信息")
    public Result<UserVo> getUserInfo (){
        Long id = BaseContext.getCurrentId();
        if (id == null){
            throw new DataErrorException(MessageConstant.USER_NOT_LOGIN);
        }
        UserVo userVo = userService.getByid(id);
        return Result.success(userVo);
    }

}
